package com.zeta.plan.utils;

import org.springframework.util.DigestUtils;

import java.nio.charset.StandardCharsets;

/**
 * @ClassName MD5Util
 * @Description TODO
 * @Author zeta
 * @Date 2022/2/26 20:19
 * @Version 1.0
 **/
public class MD5Util {
    public static final int count = 996;

    public static String md5(String origin, String salt) {
        return DigestUtils.md5DigestAsHex((origin + salt).getBytes(StandardCharsets.UTF_8));
    }

    public static String md5(String origin) {
        return DigestUtils.md5DigestAsHex(origin.getBytes(StandardCharsets.UTF_8));
    }

    public static String md5(String origin, String salt, int count) {
        if (count <= 0) {
            count = MD5Util.count;
        }
        String res = origin + salt;
        for (int i = 0; i < count; i++) {
            res = md5(res);
        }
        return res;
    }
}
